package com.uobgroup.ews.uam.core.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Configurable
@NamedQueries({ @NamedQuery(name = "findRoleSubTypebyRoleType", query = "select r from RoleSubType r where r.roleType = :roleType") })
public class RoleSubType extends BaseEntity {

   public static final String QUERY_GET_ROLESUBTYPE_ROLETYPE = "findRoleSubTypebyRoleType";

   public static final String PARAM_ROLE_TYPE = "roleType";

   @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
   private Reference roleType;

   @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
   @JoinTable(name = "ROLESUBTYPEACCESSCONTROL", joinColumns = { @JoinColumn(name = "ROLESUBTYPE", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "ACCESSCONTROL", referencedColumnName = "id") })
   private List<AccessControl> accessControl;

   public List<AccessControl> getAccessControl() {
      return accessControl;
   }

   public void setAccessControl(List<AccessControl> accessControl) {
      this.accessControl = accessControl;
   }

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "id")
   private Long id;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Reference getRoleType() {
      return this.roleType;
   }

   public void setRoleType(Reference roleType) {
      this.roleType = roleType;
   }

   @NotNull
   @Size(max = 255)
   private String name;

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

}
